var jiesuan = {
	btn: $("#jiesuan"),
	click: function() {
		if($("#jiesuan").hasClass("active"))return;
		AlertView.layer.loading("正在结算(大约1分钟,请勿关闭)....");
		BC_POST.canDo({
			gameId:GameView.param.gameId,
			player:App.accounts[0],
			action: "settle"
		}).then(function(result) {

			BC.do("checkAndSettle", {
				hashId: "0x"+GameView.param.gameId
			}).then(function(result) {
				console.log();
				
				BC_WS.addObserver("state", function(data, p) {
					console.log("MainView addObserver state" + data);
					if(data.state == "5" && GameView.param.gameId == data.gameId) {
						AlertView.layer.alert("成功", "结算成功");
						GameView.ws.search(GameView.param.gameId);
						return false;
					} else {
						return true;
					}
				}, true);
				
				AlertView.layer.alert("结算成功", "您已经成功结算（可查询账户确认）");
			}).catch(function(err) {
				AlertView.layer.alert("结算失败", err.msg);
			});
		}).catch(function(err) {
			AlertView.layer.alert("结算失败", err.msg);
		});
	},
	result: function(result) {
		if(result.logs.length > 0) {
			GameView.ws.search(GameView.param.gameId);
		}
	},
	setParam:function(param){
		jiesuan.param = param;
		var html = template("jiesuanTmp",param);
		$("tr.jiesuantr").html(html);
		$("#jiesuan").on("clikc",function(){
			jiesuan.query().then(function(result){
				jiesuan.click();
			}).catch(function(err){
				AlertView.layer.alert("错误", err.msg);
			});
		});
	},
	init: function() {
		$("#jiesuan").on("click", function() {
			
		});
	}
};